//
//  DSZGZMoreViewController.m
//  7.13苏宁框架
//
//  Created by app15 on 15/7/19.
//  Copyright (c) 2015年 lovena. All rights reserved.
//

#import "DSZGZMoreViewController.h"
#import "DSZTJGroupModel.h"
#import "DSZTJSuperModel.h"
#import "MJExtension.h"
#import "DSZGZMoreCollectionViewCell.h"
#import "DSZGZViewController.h"
#import "DSZGZDRViewController.h"
#import "DSZShowViewController.h"
#import "DSZGZXQViewController.h"
@interface DSZGZMoreViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,DSZGZMoreCollectionViewCellDelegate>
{
    UICollectionView *_collection;
}
@property(nonatomic,retain)NSArray *superModel;
@end


@implementation DSZGZMoreViewController
static NSString * const ILId=@"DSZGZM";


- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadNa];
    self.title=@"达人库";
    self.view.backgroundColor=[UIColor redColor];
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
    
    // 设置每一个各自的大小
    flow.itemSize = CGSizeMake(300, 150);
    
    // 水平方向上的间距 == 0
    flow.minimumInteritemSpacing = 0;
    
    flow.sectionInset = UIEdgeInsetsMake(15, 10, 15, 10);
    _collection=[[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, 320, 533) collectionViewLayout:flow];
    _collection.backgroundColor=[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
    [self.view addSubview:_collection];
    _collection.delegate=self;
    _collection.dataSource=self;
    
    _collection.bounces=NO;
    // 3.注册
    UINib *nib = [UINib nibWithNibName:[DSZGZMoreCollectionViewCell xib] bundle:nil];
    [_collection registerNib:nib forCellWithReuseIdentifier:ILId];
    // Do any additional setup after loading the view.
}

-(void)viewWillAppear:(BOOL)animated{
    DSZShowViewController *show=(DSZShowViewController*)self.tabBarController;
    [show hiddenShowTabbar:YES];
}
-(void)nextView{
    DSZGZDRViewController *view=[[DSZGZDRViewController alloc]init];
    [self.navigationController pushViewController:view animated:NO];
}
-(void)detailView{
    DSZGZXQViewController *view=[[DSZGZXQViewController alloc]init];
    [self.navigationController pushViewController:view animated:NO];
}

-(void)loadNa{
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 44)];
    UIButton *button=[UIButton buttonWithType:UIButtonTypeSystem];
    button=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 25, 40)];
    [button setImage:[UIImage imageNamed:@"back_black_icon"]  forState:UIControlStateNormal];
    [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];
    UIBarButtonItem *barbutton=[[UIBarButtonItem alloc]initWithCustomView:view];
    self.navigationItem.leftBarButtonItem=barbutton;
    
    UIView *view1=[[UIView alloc]initWithFrame:CGRectMake(250, 0, 20, 44)];
    UIButton *button1=[UIButton buttonWithType:UIButtonTypeSystem];
    button1=[[UIButton alloc]initWithFrame:CGRectMake(260, 0, 25, 40)];
    [button1 setImage:[UIImage imageNamed:@"SNPM_search"]  forState:UIControlStateNormal];
    [view addSubview:button1];
    UIBarButtonItem *barbutton1=[[UIBarButtonItem alloc]initWithCustomView:view1];
    self.navigationItem.rightBarButtonItem=barbutton1;
 }
-(void)back{
    DSZShowViewController *show=(DSZShowViewController*)self.tabBarController;
    [show hiddenShowTabbar:NO];
    [self.navigationController popToRootViewControllerAnimated:NO];
}
//plist文件的数组
-(NSArray*)superModel{
    //plist文件的数组
    NSArray *array=[NSArray array];
    array=[DSZTJSuperModel modelArrayWithFilename:@"Show.plist"];
    return _superModel=array;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.superModel.count;
}

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    DSZTJSuperModel *model=_superModel[indexPath.row];
    
    NSDictionary *dic=[model keyValues];
    NSArray *groupArray=dic[@"group"];
    NSArray *groupModelArray=[DSZTJGroupModel modelArrayWithDictArray:groupArray];
    DSZGZMoreCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:ILId forIndexPath:indexPath];
    cell.delegate=self;
    [cell groupModel:groupModelArray model:model];
    cell.superImageView.image=[UIImage imageNamed:model.image];
    //cell.backgroundColor=[UIColor grayColor];
    return cell;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
